package com.sctvcloud.longchang.ui.activities;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.jiongbull.jlog.JLog;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.longchang.R;
import com.sctvcloud.longchang.base.BaseActivity;
import com.sctvcloud.longchang.beans.EncyclopediaVo;
import com.sctvcloud.longchang.beans.LeaderMailBean;
import com.sctvcloud.longchang.http.AbsNetCallBack;
import com.sctvcloud.longchang.http.NetUtils;
import com.sctvcloud.longchang.ui.utils.TitleUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 领导信箱
 */
public class LeaderMailActivity extends BaseActivity {
    @BindView(R.id.secretary_mailbox)
    protected ImageView secretary_mailbox;
    @BindView(R.id.mayors_mailbox)
    protected ImageView mayors_mailbox;
    private String channelUrl = "sctv/leaderMailbox.json";
    private LeaderMailBean leaderMailBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new TitleUtils(this).setBackVisible(true).useAndSetTxTitle("领导信箱");
        getChannelList();
    }

    @Override
    protected void initInject() {
        setContentView(R.layout.activity_leader_mail);
        ButterKnife.bind(this);
    }

    /**
     * 获取模块 多个类型的显示数据。
     */
    private void getChannelList() {
        showProgress("正在加载...");
        NetUtils.getNetAdapter().getLeaderMail(getOwnerName(), channelUrl, new AbsNetCallBack<LeaderMailBean>(LeaderMailBean.class) {
            @Override
            public void onSuc(LeaderMailBean vo) {
                leaderMailBean = vo;
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
            }

            @Override
            public void onEnd() {
                super.onEnd();
                closeProgress();
            }

        });
    }


    @OnClick({R.id.secretary_mailbox, R.id.mayors_mailbox})
    protected void OnClick(View view) {
        if (null != leaderMailBean) {
            if (view.getId() == R.id.secretary_mailbox) {
                Intent intent = new Intent(this, H5NormalActivity.class);
                intent.putExtra(H5NormalActivity.EX_HTML, leaderMailBean.getSecretaryMailbox());
                intent.putExtra(H5NormalActivity.IS_NEED_SHARE, false);
                startActivity(intent);
            } else if (view.getId() == R.id.mayors_mailbox) {
                Intent intent = new Intent(this, H5NormalActivity.class);
                intent.putExtra(H5NormalActivity.EX_HTML, leaderMailBean.getMayorMailbox());
                intent.putExtra(H5NormalActivity.IS_NEED_SHARE, false);
                startActivity(intent);
            }
        } else {
            toast("数据异常，请重试");
        }
    }
}
